package com.cupcorn.balapkarung.state;

import com.cupcorn.balapkarung.entity.MC;
import com.cupcorn.lib.game.GameEngine;
import com.cupcorn.onlinescript.OnlineScript;

public class StateGamePlayOnline
{
	MC[]			mc;
	StateGamePlay	gamePlay;
	
	public StateGamePlayOnline(GameEngine engine, StateGamePlay gamePlay)
	{
		this.mc = StateGamePlay.mc;
		this.gamePlay = gamePlay;
		
		for (int i = 1; i < StateGamePlay.MAX_MC_COUNT; i++)
		{
			mc[i] = new MC(engine, gamePlay.displayAnimatedSprite.newAnimatedSprite(0), "", null);
			resetPosition(i);
		}
	}
	
	public void update(float deltaTime)
	{
		for (int i = 1; i < StateGamePlay.MAX_MC_COUNT; i++)
		{
			mc[i].replay(OnlineScript.object[i - 1].getArrayValue_());
			mc[i].onUpdate(deltaTime);
		}
	}
	
	public void reset()
	{
		for (int i = 1; i < StateGamePlay.MAX_MC_COUNT; i++)
		{
			mc[i].setName(OnlineScript.object[i - 1].getName());
			mc[i].reset();
			mc[i].switchState(mc[i].MOVE);
			mc[i].curJump = mc[i].MAX_JUMP;
			mc[i].curGravitation = 600;
			resetPosition(i);
		}
	}
	
	public void resetPosition(int i)
	{
		if (i < 2)
			mc[i].mc.setPosition(mc[i - 1].mc.getX() + mc[0].mc.getWidth(), -(mc[i].mc.getHeight() * 2));
		else if (i == 2)
			mc[i].mc.setPosition(mc[i - 2].mc.getX() - mc[0].mc.getWidth(), -(mc[i].mc.getHeight() * 1.5f));
		else
			mc[i].mc.setPosition(mc[i - 1].mc.getX() - mc[0].mc.getWidth(), -(mc[i].mc.getHeight() * 1));
	}
	
}